﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using School.Common;
using School.Entities;
namespace School.Pages.UserControls
{
    
    public partial class evaluation : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
               
                ddlCampus.DataSource = allcampous();
                ddlCampus.DataValueField = "Id";
                ddlCampus.DataTextField = "Name";
                ddlCampus.DataBind();
               
                
                
                
                ddlcer.Items.Insert(0, new ListItem( "اختيار", "0"));
                ddlStage.Items.Insert(0, new ListItem( "اختيار", "0"));
                ddlGrade.Items.Insert(0, new ListItem( "اختيار", "0"));
                ddlsubject.Items.Insert(0, new ListItem( "اختيار", "0"));
                ddlclass.Items.Insert(0, new ListItem( "اختيار", "0"));
                ddlevaluation_type.Items.Insert(0, new ListItem( "اختيار", "0"));
                ddlCampus.Items.Insert(0, new ListItem() { Value = "0", Text = "اختيار" });
                
            }
           
        }

          private void ddlBind(DropDownList ddl)
        {
            ddl.Items.Clear();
            ddl.Items.Insert(0, new ListItem("اختيار", "0"));
            ddl.DataBind();
        }


        public static SchoolEntities db = new SchoolEntities();

        public static IEnumerable<ORG_Grade> GetGrades(int x)
        {
            var q1 = (from r in db.ORG_Grade where r.Stage_Id == x select r).ToList();
            return q1;

        }

        public static IEnumerable<ORG_Stage> Getstages(int x)
        {
            var q1 = (from r in db.ORG_Stage where r.Certificate_Id == x select r).ToList();
            return q1;

        }
        public static IEnumerable<ORG_Certificate> Getcertificates(int x)
        {
            var q1 = (from r in db.ORG_Certificate where r.Campus_Id == x select r).ToList();
            return q1;

        }

        public static IEnumerable<TE_Evaluation_Type> getevatype()
        {
            var q1 = (from r in db.TE_Evaluation_Type
                     select r).ToList();
            return q1;
        }
        public static IEnumerable<TE_Subject> GetSubject(int x)
        {
            var q1 = (from r in db.TE_Subject
                      where r.Grad_Id == x
                      select r).ToList();
            return q1;

        }

        public static IEnumerable<ORG_Campus> allcampous( )
        {
            var q1 = (from r in db.ORG_Campus
                      select r).ToList();
            return q1;

        }

        public static IEnumerable<ORG_Class> getclass(int x)
        {
            var q1 = (from r in db.ORG_Class
                      where r.Grade_Id == x
                      select r).ToList();
            return q1;

        }
        protected void ddlCampus_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlCampus.SelectedValue != "0")
            {

                ddlcer.DataSource = Getcertificates(int.Parse(ddlCampus.SelectedValue));
                ddlcer.DataValueField = "Id";
                ddlcer.DataTextField = "Name";
                ddlcer.DataBind();
                ddlcer.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlStage.Items.Clear();
                ddlStage.Items.Clear();
                ddlGrade.Items.Clear();
                ddlsubject.Items.Clear();
                ddlclass.Items.Clear();
                ddlevaluation_type.Items.Clear();
                ddlStage.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlGrade.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlsubject.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlclass.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlevaluation_type.Items.Insert(0, new ListItem("اختيار", "0"));
              
            }
            else if (ddlCampus.SelectedValue == "0")
            {
                ddlcer.Items.Clear();
                ddlStage.Items.Clear();
                ddlGrade.Items.Clear();
                ddlsubject.Items.Clear();
                ddlclass.Items.Clear();
                ddlevaluation_type.Items.Clear();
                ddlcer.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlStage.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlGrade.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlsubject.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlclass.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlevaluation_type.Items.Insert(0, new ListItem("اختيار", "0"));

            }
           
        }

        protected void ddlcer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlcer.SelectedValue != "0")
            {
                ddlStage.DataSource = Getstages(int.Parse(ddlcer.SelectedValue));
                ddlStage.DataValueField = "Id";
                ddlStage.DataTextField = "Name";
                ddlStage.DataBind();
                ddlStage.Items.Insert(0, new ListItem("اختيار", "0"));
               
               
                ddlGrade.Items.Clear();
                ddlsubject.Items.Clear();
                ddlclass.Items.Clear();
                ddlevaluation_type.Items.Clear();
              
                ddlGrade.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlsubject.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlclass.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlevaluation_type.Items.Insert(0, new ListItem("اختيار", "0"));
            }
            else
            {
                
                ddlStage.Items.Clear();
                ddlGrade.Items.Clear();
                ddlsubject.Items.Clear();
                ddlclass.Items.Clear();
                ddlevaluation_type.Items.Clear();
                ddlStage.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlGrade.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlsubject.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlclass.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlevaluation_type.Items.Insert(0, new ListItem("اختيار", "0")); 
            }
        }

        protected void ddlStage_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(ddlStage.SelectedValue!="0" )
            {
                ddlGrade.DataSource = GetGrades(int.Parse(ddlStage.SelectedValue));
                ddlGrade.DataValueField = "Id";
                ddlGrade.DataTextField = "Name";
                ddlGrade.DataBind();
                ddlGrade.Items.Insert(0, new ListItem("اختيار", "0"));
            }
            else
            {

              
                ddlGrade.Items.Clear();
                ddlsubject.Items.Clear();
                ddlclass.Items.Clear();
                ddlevaluation_type.Items.Clear();
                ddlGrade.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlsubject.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlclass.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlevaluation_type.Items.Insert(0, new ListItem("اختيار", "0"));
            }
        }

        protected void ddlGrade_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(ddlGrade.SelectedValue!="0" )
            { ddlsubject.DataSource=GetSubject(int.Parse(ddlGrade.SelectedValue));
            ddlsubject.DataValueField = "Id";
            ddlsubject.DataTextField = "Subject_Name";
            ddlsubject.DataBind();
            ddlclass.DataSource = getclass(int.Parse(ddlGrade.SelectedValue));
            ddlclass.DataValueField = "Id";
            ddlclass.DataTextField = "Name";
            ddlclass.DataBind();
            ddlevaluation_type.DataSource = getevatype();
            ddlevaluation_type.DataValueField = "Id";
            ddlevaluation_type.DataTextField = "Name";
            ddlevaluation_type.DataBind();
            ddlclass.Items.Insert(0, new ListItem("اختيار", "0"));
            ddlevaluation_type.Items.Insert(0, new ListItem("اختيار", "0"));
            ddlsubject.Items.Insert(0, new ListItem("اختيار", "0"));
           
            }
            else
            {


              
                ddlsubject.Items.Clear();
                ddlclass.Items.Clear();
                ddlevaluation_type.Items.Clear();
              
                ddlsubject.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlclass.Items.Insert(0, new ListItem("اختيار", "0"));
                ddlevaluation_type.Items.Insert(0, new ListItem("اختيار", "0"));
            }
        }

       

     

     
        

       
        
        
        
        
        
  
    }
}